# -*-utf-8-*-

import os
from re import L
import shutil

import cv2
import numpy as np
import time
import random
from tool import filesystem


def getDir():
    """获取文件路径"""
    checkDir = r"F:\work\code\paddle\train_data\cls\car\images\2\15\car"
    dataDir = r"F:\work\code\paddle\train_data\cls\car\images\2022\2-1\15\car"

    saveDir = r"F:\work\code\paddle\train_data\cls\car\images\2022\2-1\check"
    return checkDir, dataDir, saveDir


def getFiles(path):
    """从路径中获取文件名"""
    fileName = []
    for f in path:
        files = os.path.basename(f)
        name = "#".join(files.split("#")[: 2])
        fileName.append(name)
    

    return fileName


def check(checkDir, dataDir):
    """文件检查"""
    datafilesPath = filesystem.get_all_filepath(dataDir, '.jpg')
    datafilesName = getFiles(datafilesPath)
    
    checkfilesPath = filesystem.get_all_filepath(checkDir, '.jpg')
    CheckfilesName = getFiles(checkfilesPath)

    files = []
    for inx, f in enumerate(CheckfilesName):
        if not f in datafilesName:
            files.append(checkfilesPath[inx])

    return files


def printFiles(files):
    """打印文件名"""
    # for f in files:
    #     print(f)
    # print(files)
    print(files[0])
    print(len(files))

def fileSave(files, dir, srcPath):
    """复制文件"""
    for f in files:
        
        savePath = os.path.join(srcPath, f)
        print(savePath)
        shutil.copy(savePath, dir)

def main():
    """主方法"""
    checkDir, dataDir, saveDir = getDir()
    checkFiles = check(checkDir, dataDir)
    fileSave(checkFiles, saveDir, checkDir)
    printFiles(checkFiles)


if __name__ == "__main__":
    main()